﻿#ifndef _ICONV_STRING_H_
#define _ICONV_STRING_H_

#include "BaseDef.h"
#include "Stdafx.h"
#include <string>
#include <string.h>
using namespace std;

class  StringTransform
{
	//函数定义
public:
	//构造函数
	StringTransform();
	//析构函数
	virtual ~StringTransform();

public:
	void codeConvertInit();
	void codeConvertDestroy();

	//编码转换
	void			wstringToUTF8(std::string& dest, const wstring& src);
	int				unicodeToUTF8(const wchar_t * wstr, string &out_str);
	int				utf8ToUnicode(const char* str, wstring &out_wstr);
	string			wstringToString(const std::wstring& ws);
	wstring			stringToWstring(const std::string& s);
	std::string		utf8ToGbk(const char* src);
	std::string		gbkToUTF8(const char* src);
	std::wstring	ansiToUnicode(const char* buf);
	std::string		unicodeToAnsi(const wchar_t* buf);
	std::string		GbToUTF8(const char *inbuf);				/*GB2312 to UTF8*/
	std::string		utf8ToGb(const char *inbuf);				/*UTF8 to GB2312*/
	bool			IsLegitimateChrName(const char* name);
	bool			IsLegitimateAccountName(const char* name);
	bool			IsAllNum(const char* str);

private:
	int				code_convert(const char *from_charset, const char *to_charset, const char *inbuf, size_t inlen, char *outbuf, size_t outlen);
	std::string		utf8ToGbk(char src[]);
	std::string		gbkToUTF8(char src[]);
};

#endif
